Rsync - Synchronizes files and directories
2014/08/26 |
Synchronizes files and directories from one location to another by rsync.
Basic usage of rsync is here.
The example below is for automatical settings.
Ecxample ⇒ Copy files and directories in /var/www/html on a HostA[10.0.0.31] to in /home/backup on HostB[10.0.0.30].
|
|
[1] | Configure on Destination Host. |
[root@dlp ~]#
yum -y install rsync xinetd
[root@dlp ~]#
vi /etc/xinetd.d/rsync
# default: off
[root@dlp ~]# # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = no # change flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } /etc/rc.d/init.d/xinetd start Starting xinetd: [ OK ]
[root@dlp ~]#
[root@dlp ~]# chkconfig xinetd on mkdir /home/backup
[root@dlp ~]#
vi /etc/rsyncd.conf # any name you like [website] # destination directory path = /home/backup # Hosts you allow to copy (specify source Host) hosts allow = 10.0.0.31 hosts deny = * list = true uid = root gid = root read only = false |
[2] | Configure on Source Host. |
[root@www ~]#
yum -y install rsync
[root@www ~]#
vi /etc/rsync_exclude.lst # specify files or directories you'd like to exclude to copy
test test.txt |
[3] | It's OK. Execute rsync on Source Host like follows. |
[root@www ~]#
rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /var/www/html/ 10.0.0.30::website # Add in cron if you'd like to run reguraly
[root@www ~]#
crontab -e # run at 2:00 AM in a day 00 02 * * * rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /var/www/html/ 10.0.0.30::website
|